home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.FileDialog;
- import java.awt.Frame;
- import java.awt.Label;
- import java.awt.LayoutManager;
- import java.awt.List;
- import java.awt.Menu;
- import java.awt.MenuBar;
- import java.awt.MenuItem;
- import java.util.Enumeration;
- import java.util.Vector;
-
- public class Frame1 extends Frame {
- Vector thingsInStock;
- Vector thingsInBasket;
- FileDialog OpenFileDialog;
- List StockList;
- List BasketList;
- Label label1;
- Label label2;
- Label label3;
- Label label4;
- MenuBar mainMenuBar;
- Menu menu1;
- Menu menu2;
- Menu menu3;
-
- void MoveObFromV1ToV2(Object Ob, Vector V1, Vector V2) {
- V2.addElement(Ob);
- V1.removeElement(Ob);
- }
-
- void BasketList_DblClick(Event event) {
- Object thing = this.thingsInBasket.elementAt(this.BasketList.getSelectedIndex());
- this.MoveObFromV1ToV2(thing, this.thingsInBasket, this.thingsInStock);
- this.UpdateListBoxes();
- }
-
- void StockList_DblClick(Event event) {
- Object thing = this.thingsInStock.elementAt(this.StockList.getSelectedIndex());
- this.MoveObFromV1ToV2(thing, this.thingsInStock, this.thingsInBasket);
- this.UpdateListBoxes();
- }
-
- void UpdateListBox(List l, Vector v) {
- l.clear();
- Enumeration e = v.elements();
-
- while(e.hasMoreElements()) {
- l.addItem(e.nextElement().toString());
- }
-
- }
-
- void UpdateListBoxes() {
- this.UpdateListBox(this.BasketList, this.thingsInBasket);
- this.UpdateListBox(this.StockList, this.thingsInStock);
- }
-
- void Open_Action(Event event) {
- this.OpenFileDialog.show();
- }
-
- void About_Action(Event event) {
- (new AboutDialog(this, "About...", false)).show();
- }
-
- void Exit_Action(Event event) {
- (new QuitDialog(this, "Quit the Application?", false)).show();
- }
-
- public Frame1() {
- ((Container)this).setLayout((LayoutManager)null);
- ((Frame)this).addNotify();
- ((Component)this).resize(((Container)this).insets().left + ((Container)this).insets().right + 457, ((Container)this).insets().top + ((Container)this).insets().bottom + 322);
- this.OpenFileDialog = new FileDialog(this, "Open", 0);
- this.StockList = new List(0, false);
- ((Container)this).add(this.StockList);
- this.StockList.reshape(((Container)this).insets().left + 14, ((Container)this).insets().top + 45, 201, 225);
- this.BasketList = new List(0, false);
- ((Container)this).add(this.BasketList);
- this.BasketList.reshape(((Container)this).insets().left + 238, ((Container)this).insets().top + 45, 201, 225);
- this.label1 = new Label("ITEMS IN STOCK");
- this.label1.reshape(((Container)this).insets().left + 14, ((Container)this).insets().top + 15, 196, 15);
- ((Container)this).add(this.label1);
- this.label2 = new Label("ITEMS IN YOUR BASKET");
- this.label2.reshape(((Container)this).insets().left + 238, ((Container)this).insets().top + 15, 203, 15);
- ((Container)this).add(this.label2);
- this.label3 = new Label("DOUBLE-CLICK TO BUY");
- this.label3.reshape(((Container)this).insets().left + 14, ((Container)this).insets().top + 278, 203, 22);
- ((Container)this).add(this.label3);
- this.label4 = new Label("DOUBLE-CLICK TO PUT BACK");
- this.label4.reshape(((Container)this).insets().left + 238, ((Container)this).insets().top + 278, 203, 24);
- ((Container)this).add(this.label4);
- ((Frame)this).setTitle("A Basic Application");
- this.mainMenuBar = new MenuBar();
- this.menu1 = new Menu("File");
- this.menu1.add("Open...");
- this.menu1.add("Save");
- this.menu1.add("Save As...");
- this.menu1.addSeparator();
- this.menu1.add("Exit");
- this.mainMenuBar.add(this.menu1);
- this.menu2 = new Menu("Edit");
- this.menu2.add("Cut");
- this.menu2.add("Copy");
- this.menu2.add("Paste");
- this.mainMenuBar.add(this.menu2);
- this.menu3 = new Menu("Help");
- this.menu3.add("About");
- this.mainMenuBar.add(this.menu3);
- ((Frame)this).setMenuBar(this.mainMenuBar);
- }
-
- public Frame1(String title) {
- this();
- ((Frame)this).setTitle(title);
- }
-
- public synchronized void show() {
- ((Component)this).move(50, 50);
- super.show();
- this.thingsInStock = new Vector();
- this.thingsInBasket = new Vector();
- this.thingsInStock.addElement("Tin of Schpamm");
- this.thingsInStock.addElement("Pot of Schnoodles");
- this.thingsInStock.addElement("Jug of Hare");
- this.thingsInStock.addElement("Kettle of Fish");
- this.thingsInStock.addElement("Bombay Duck");
- this.thingsInStock.addElement("Duck-billed platypus");
- this.thingsInStock.addElement("Can of worms");
- this.thingsInStock.addElement("Hair of the dog");
- this.thingsInStock.addElement("Dog's bone");
- this.thingsInStock.addElement("PC Plus");
- this.UpdateListBoxes();
- }
-
- public boolean handleEvent(Event event) {
- if (event.id == 201) {
- ((Component)this).hide();
- ((Frame)this).dispose();
- System.exit(0);
- return true;
- } else {
- if (event.target == this.StockList && event.id == 1001) {
- this.StockList_DblClick(event);
- }
-
- if (event.target == this.BasketList && event.id == 1001) {
- this.BasketList_DblClick(event);
- }
-
- return super.handleEvent(event);
- }
- }
-
- public boolean action(Event event, Object arg) {
- if (event.target instanceof MenuItem) {
- String label = (String)arg;
- if (label.equalsIgnoreCase("Open...")) {
- this.Open_Action(event);
- return true;
- }
-
- if (label.equalsIgnoreCase("About")) {
- this.About_Action(event);
- return true;
- }
-
- if (label.equalsIgnoreCase("Exit")) {
- this.Exit_Action(event);
- return true;
- }
- }
-
- return super.action(event, arg);
- }
-
- public static void main(String[] args) {
- (new Frame1()).show();
- }
- }
-